package com.net.library.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import okhttp3.Interceptor;

/**
 * author 吴昶
 * date 2019/6/3
 * 标注
 */
public class SharedPreferencesUntil {

    private static SharedPreferences share;

    public static void initShare(Context context,String name){
        share=context.getSharedPreferences(name, Activity.MODE_PRIVATE);
    }

    @SuppressLint("CommitPrefEdits")
    public static void saveValue(String key, Object value){
        if(value instanceof Integer){
            share.edit().putInt(key,(Integer)value).apply();
        }else if(value instanceof Boolean){
            share.edit().putBoolean(key,(Boolean)value).apply();
        }else if(value instanceof String){
            share.edit().putString(key,(String) value).apply();
        }else if(value instanceof Float){
            share.edit().putFloat(key,(Float) value).apply();
        }else if(value instanceof Long){
            share.edit().putLong(key,(Long) value).apply();
        }
    }

    public static Object getValue(String key, Object value) {
        if(value instanceof Integer){
            return  share.getInt(key,(Integer) value);
        }else if(value instanceof Boolean){
            return  share.getBoolean(key,(Boolean) value);
        }else if(value instanceof String){
            return  share.getString(key,(String) value);
        }else if(value instanceof Float){
            return  share.getFloat(key,(Float) value);
        }else if(value instanceof Long){
            return  share.getLong(key,(Long) value);
        }
        return value;
    }
}
